home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Src / qmgr / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.3 KB  |  79 lines

  1. /* misc.c: misc routines required by qmgr */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Src/qmgr/RCS/misc.c,v 6.0 1991/12/18 20:27:38 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Src/qmgr/RCS/misc.c,v 6.0 1991/12/18 20:27:38 jpo Rel $
  9.  *
  10.  * $Log: misc.c,v $
  11.  * Revision 6.0  1991/12/18  20:27:38  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "types.h"
  19.  
  20. int    hash (str, n) /* case independant hash function */
  21. char    *str;
  22. int    n;
  23. {
  24.     extern char chrcnv[];
  25.     int    res = 0;
  26.     char    *cp;
  27.  
  28.     for (cp = str; *cp; cp++) {
  29.         res = 3 * res + chrcnv[*cp];
  30.         res %= n;
  31.     }
  32.     return res;
  33. }
  34.  
  35. void cache_set (cp, utct)
  36. Cache    *cp;
  37. struct type_UNIV_UTCTime *utct;
  38. {
  39.     cp -> cachetime = utcqb2time_t (utct);
  40.     cp -> cacheplus = 0;
  41. }
  42.  
  43. void cache_clear (cp)
  44. Cache *cp;
  45. {
  46.     cp -> cachetime = cp -> cacheplus = 0;
  47. }
  48.  
  49. void cache_inc (cp, factor)
  50. Cache *cp;
  51. time_t    factor;
  52. {
  53.     int rfact;
  54.  
  55.     if (cp -> cacheplus < CACHE_MAX)
  56.         cp -> cacheplus ++;
  57.     cp -> cachetime = current_time + factor * cp -> cacheplus;
  58.  
  59.     /* round up the cache time - helps cluster mta's etc. */
  60.     rfact = (factor/10) * cp -> cacheplus;
  61.     if (rfact <= 0)
  62.         rfact = 1;
  63.     cp -> cachetime += rfact - cp -> cachetime % rfact;
  64. }
  65.  
  66. time_t    utcqb2time_t (qb)
  67. struct qbuf *qb;
  68. {
  69.     char *p = qb2str (qb);
  70.     UTC    ut;
  71.     time_t    t;
  72.  
  73.     ut = str2utct(p, strlen (p));
  74.     t = utc2time_t (ut);
  75.     free (p);
  76.     return t;
  77. }
  78.  
  79.